$(document).ready(function() {
    $('.window .close').click(function (e) {
	e.preventDefault();
	$('#modal_mask, .window').hide();
    });

    $("#modal_mask").click(function () {
	$(this).hide();
	$('.window').hide();
    });
});

function modal_show() {
    var id = "#dialog";
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    var mask = $('#modal_mask');
    mask.css({'top': 0, 'left': 0});
    mask.css({'width': maskWidth, 'height': maskHeight});
    mask.fadeIn(1000);
    mask.fadeTo("slow", 0.8);

    var winH = $(window).height();
    var winW = maskWidth;
    $(id).css('top', winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);
    $(id).fadeIn(2000);
}

function modal_show_image(image) {
    var content = $('#modal_content');
    content.css({'width': '400px'});
    content.empty();
    content.append($(jQuery('<img>'))
		   .attr("src", image)
		   .attr("id", "modal_image")
		   .load(function() { modal_show() }));
}